package com.jetinno.utils

import com.google.gson.reflect.TypeToken
import com.jetinno.utils.Preference.Companion.prefs

/**
 * Created by zhangyuncai on 2023/4/11.
 * 这里获取的是数据库中常用的一些字段值,而且是所有仓库都用得到的,只get不能set
 */
object JGlobal {
    private const val GLOBALTEXT = "globalText"

    /**
     * {@link Global}
     */
    @JvmStatic
    fun getGlobal(): HashMap<String, Any> {
        val json = prefs.getString(GLOBALTEXT, "")
        val type = object : TypeToken<HashMap<String, Any>>() {}.type
        val map = JsonUtil.jsonToAny<HashMap<String, Any>>(json, type) ?: hashMapOf()
        return map
    }

    @JvmStatic
    fun <T> getValueInGlobal(key: String, default: T): T {
        return (getGlobal().get(key) ?: default) as T
    }

    @JvmStatic
    fun <T> getValueInShare(key: String, default: T): T {
        return Preference.getValue(key, default)
    }

    @JvmStatic
    val doorCardBaudRate: Int
        get() = getValueInGlobal("doorCardBaudRate", 115200)

    @JvmStatic
    val ioBaudRate: Int
        get() = getValueInGlobal("ioBaudRate", 9600)

    @JvmStatic
    val barCodeBaudRate: Int
        get() = getValueInGlobal("barCodeBaudRate", 9600)

    @JvmStatic
    val isDebug by Preference("isDebug", false)//是否DEBUG模式启动APP

    @JvmStatic
    val apkBuildTime by Preference("apkBuildTime", "")//APP打包时间

    @JvmStatic
    val isSimulator by Preference("isSimulator", false)//是否是模拟器
}